package com.vhall.component.service.vote.delay;

import lombok.Data;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @author jingwen.li
 */
@Data
public class DelayEvent implements Delayed {

    private long voteId;

    private String roomId;

    private long delayTime;

    private Integer accountId;

    public DelayEvent(long voteId, long delayTime, String roomId){
        super();
        this.voteId = voteId;
        // 延迟时间加当前时间
        this.delayTime = System.currentTimeMillis() + delayTime * 1000;
        this.roomId = roomId;
    }

    @Override
    public long getDelay(@NotNull TimeUnit unit) {
        return unit.convert(delayTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(@NotNull Delayed o) {
        return Long.compare(delayTime, ((DelayEvent) o).delayTime);
    }
}
